package com.zshan.clinic.cms.controller.clinic;


import com.zshan.clinic.admin.entity.vo.ClinicMenuTreeVo;
import com.zshan.clinic.admin.service.clinic.ClinicAuthService;
import com.zshan.clinic.cms.common.core.controller.BaseController;
import com.zshan.clinic.cms.common.core.domain.AjaxResult;
import com.zshan.clinic.cms.common.core.domain.entity.SysUser;
import com.zshan.clinic.common.enums.ReqSourceEnum;
import com.zshan.clinic.database.model.ClinicMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 诊所信息
 */
@RestController
@RequestMapping("/clinic/auth")
public class ClinicAuthController extends BaseController {


    @Autowired
    private ClinicAuthService clinicAuthService;

    /**
     * 获取菜单列表
     * @param menuName
     * @return
     */
    @GetMapping("/getMenuTree")
    public AjaxResult getMenuTree(@RequestParam(name = "menuName",required = false) String menuName){
        List<ClinicMenuTreeVo> menuList = clinicAuthService.getMenuTree(menuName, ReqSourceEnum.ADMIN.getValue());
        return AjaxResult.success(menuList);
    }

    /**
     * 添加菜单
     * @param clinicMenu
     * @return
     */
    @PostMapping("/addMenu")
    public AjaxResult addMenu(@RequestBody ClinicMenu clinicMenu) {
        SysUser sysUser = getUser();
        clinicMenu.setCreateUserId(sysUser.getUserId());
        clinicMenu.setCreateBy(sysUser.getUserName());
        clinicAuthService.addMenu(clinicMenu);
        return AjaxResult.success();
    }

    /**
     * 修改菜单
     * @param clinicMenu
     * @return
     */
    @PostMapping("/updateMenu")
    public AjaxResult updateMenu(@RequestBody ClinicMenu clinicMenu) {
        SysUser sysUser = getUser();
        clinicMenu.setUpdateUserId(sysUser.getUserId());
        clinicMenu.setUpdateBy(sysUser.getUserName());
        clinicAuthService.updateMenu(clinicMenu);
        return AjaxResult.success();
    }

    /**
     * 删除菜单
     * @param clinicMenu
     * @return
     */
    @PostMapping("/deleteMenu")
    public AjaxResult deleteMenu(@RequestBody ClinicMenu clinicMenu) {
        SysUser sysUser = getUser();
        clinicMenu.setUpdateUserId(sysUser.getUserId());
        clinicMenu.setUpdateBy(sysUser.getUserName());
        clinicAuthService.deleteMenu(clinicMenu);
        return AjaxResult.success();
    }

    /**
     * 启用菜单
     * @param clinicMenu
     * @return
     */
    @PostMapping("/enableMenu")
   public AjaxResult enableMenu(@RequestBody ClinicMenu clinicMenu) {
        SysUser sysUser = getUser();
        clinicMenu.setUpdateUserId(sysUser.getUserId());
        clinicMenu.setUpdateBy(sysUser.getUserName());
        clinicAuthService.enableMenu(clinicMenu);
        return AjaxResult.success();
    }

    /**
     * 停用菜单
     * @param clinicMenu
     * @return
     */
    @PostMapping("/disableMenu")
    public AjaxResult disableMenu(@RequestBody ClinicMenu clinicMenu) {
        SysUser sysUser = getUser();
        clinicMenu.setUpdateUserId(sysUser.getUserId());
        clinicMenu.setUpdateBy(sysUser.getUserName());
        clinicAuthService.disableMenu(clinicMenu);
        return AjaxResult.success();
    }

}
